fix nix packaging#440
Conversation
On NixOS, running dynamically linked programs intended for generic Linux environments is not possible. This patch allows for configuring a binary path at build time so that the Postgres version from the nixpkgs can be used instead.
| "log_min_messages": "PANIC", // Only log PANIC level messages | ||
| "log_statement": "none", // Don't log SQL statements | ||
| "log_min_duration_statement": "-1", // Don't log slow queries | ||
| "unix_socket_directories": runtimePath, // Use a directory that is guaranteed to exist |
There was a problem hiding this comment.
This was added because the default directory Postgres uses to create the lockfiles may not exist. Using runtimePath ensures the directory exists before Postgres starts.
Greptile SummaryThis PR updates Nix packaging so embedded Postgres can use Nix-provided binaries. The main changes are:
Confidence Score: 3/5This should be fixed before merging.
nix/pgschema.nix Important Files Changed
Reviews (1): Last reviewed commit: "configure postgres binary path when buil..." | Re-trigger Greptile |
| "-X" | ||
| "github.com/pgplex/pgschema/cmd.BuildDate=${buildDate}" | ||
| "-X" | ||
| "github.com/pgplex/pgschema/internal/postgres.binariesPath=${postgres}" |
There was a problem hiding this comment.
Wrong binary directory The injected value points at the PostgreSQL package root, but
embedded-postgres checks and runs pg_ctl under <binariesPath>/bin/pg_ctl. A Nix PostgreSQL package exposes pg_ctl from its bin output, so split-output packages can put the executable under ${postgresql.bin}/bin/pg_ctl rather than ${postgresql}/bin/pg_ctl. In that case the Nix-built pgschema still cannot start embedded Postgres and fails before planning.
Context Used: CLAUDE.md (source)
| "-X" | ||
| "github.com/pgplex/pgschema/cmd.BuildDate=${buildDate}" | ||
| "-X" | ||
| "github.com/pgplex/pgschema/internal/postgres.binariesPath=${postgres}" |
There was a problem hiding this comment.
Pinned server mismatch This always injects the default Nix PostgreSQL package, while
StartEmbeddedPostgres still selects an embedded-postgres version from the target database. If the target database is a different major version from the Nix package, the code asks embedded-postgres for one version but actually runs another version's initdb and postgres binaries. Planning against a PostgreSQL 14 or 15 target on a package set whose default is 17 can validate desired state with the wrong server version.
Context Used: CLAUDE.md (source)
|
@vkcku I am not familiar with nix, could you pls take a look at the review comments? |
There was a problem hiding this comment.
Pull request overview
This PR fixes Nix/NixOS packaging so pgschema can start embedded PostgreSQL using the Nix-provided Postgres binaries (instead of downloading/using generic Linux binaries that may not run on NixOS). It does this by injecting a Postgres binaries path at build time via Go -ldflags, and wiring that into the embedded Postgres startup configuration.
Changes:
- Add an overridable
postgresqlargument to the Nix derivation and pass its store path into the Go binary via-X ...internal/postgres.binariesPath=.... - Add an
internal/postgrespackage-levelbinariesPathvariable intended for ldflags injection and plumb it into embedded-postgres viaBinariesPath(...). - Add
unix_socket_directoriesto embedded Postgres start parameters, pointing at the runtime directory.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| nix/pgschema.nix | Adds a postgresql override and injects the selected Postgres path into the Go build via ldflags. |
| internal/postgres/embedded.go | Accepts an ldflags-injected binaries path and configures embedded-postgres to use it (plus sets a safer socket directory). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Running
pgschemathat is built by nix on NixOS is not possible since NixOS cannot run dynamically linked executables for general Linux environments. This works around that by providing the path to the Postgres binaries built using nix via ldflags.This has an added benefit that users can override the postgresql package being used by
embeddedpostgres.